﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace CameraWin
{
    /// <summary>
    /// 摄像头参数
    /// </summary>
    [Serializable]
    public class CameraSet
    {
        /// <summary>
        /// IP地址
        /// </summary>
        public string IP { get; set; } = "";
        /// <summary>
        /// 端口
        /// </summary>
        public int Port { get; set; } = 0;
        /// <summary>
        /// 用户名
        /// </summary>
        public string User { get; set; } = "";
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; } = "";
        /// <summary>
        /// 视频通道
        /// </summary>
        public int Channel { get; set; } = 1;
        /// <summary>
        /// 是否支持音频
        /// </summary>
        public bool Audio { get; set; }=false;
        /// <summary>
        /// 是否支持对讲
        /// </summary>
        public bool Speak {  get; set; } = false;
        /// <summary>
        /// 是否支持云台
        /// </summary>
        public bool PTZ {  get; set; }=false;
        /// <summary>
        /// 参数检查
        /// </summary>
        /// <returns></returns>
        public bool Check()
        {
            bool result = true;
            if (string.IsNullOrWhiteSpace(IP))
            {
                result = false;
            }
            IPAddress ipaddr;
            if (!IPAddress.TryParse(IP, out ipaddr))
            {
                result = false;
            }
            if (Port <= 0 || Port >= 65535)
            {
                result = false;
            }
            if (string.IsNullOrWhiteSpace(User))
            {
                result = false;
            }
            if (string.IsNullOrWhiteSpace(Password))
            {
                result = false;
            }
            if (Channel < 0)
            {
                result = false;
            }
            return result;
        }
    }
}
